<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线OJ-题目列表</title>
    <!-- 引入jquery CDN -->
    <!-- 引入jQuery库 -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- 引入jQuery Cookie插件 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <style>
        /* 起手式, 100%保证我们的样式设置可以不受默认影响 */
        * {
            /* 消除网页的默认外边距 */
            margin: 0px;
            /* 消除网页的默认内边距 */
            padding: 0px;
        }

        html,
        body {

            background-image: url("/images/background.jpg");
            background-position: center;
            background-size: cover;
            overflow: hidden;
            /* 防止滚动条出现 */
            width: 100%;
            height: 100%;
        }

        .container .navbar {
            width: 100%;
            height: 50px;
            background-color: black;
            /* 给父级标签设置overflow，取消后续float带来的影响 */
            overflow: hidden;
        }

        .container .navbar a {
            /* 设置a标签是行内块元素，允许你设置宽度 */
            display: inline-block;
            /* 设置a标签的宽度,a标签默认行内元素，无法设置宽度 */
            width: 80px;
            /* 设置字体颜色 */
            color: white;
            /* 设置字体的大小 */
            font-size: large;
            /* 设置文字的高度和导航栏一样的高度 */
            line-height: 50px;
            /* 去掉a标签的下划线 */
            text-decoration: none;
            /* 设置a标签中的文字居中 */
            text-align: center;
        }

        /* 设置鼠标事件 */
        .container .navbar a:hover {
            background-color: green;
            transform: scale(1.2);/* 在 hove 上放大字体大小r */
            transition: transform 0.3s ease, background-color 0.3s ease;/* 两个属性的平滑过渡 */
        }

        .container .navbar .login {
            float: right;
        }

        .container .question_list {
            padding-top: 50px;
            width: 800px;
            height: 100%;
            margin: 0px auto;
            /* background-color: #ccc; */
            text-align: center;
        }

        .container .question_list table {

            width: 100%;
            font-size: large;
            font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
            margin-top: 50px;
            background-color: rgba(214, 220, 221, 0.5);
        }

        .container .question_list h1 {
            color: green;
        }

        .container .question_list table .item {
            width: 100px;
            height: 40px;
            font-size: large;
            font-family: 'Times New Roman', Times, serif;
        }

        .container .question_list table .item a {
            text-decoration: none;
            color: black;
            display: block;
        }

        .container .question_list table .item a:hover {
            color: blue;
            text-decoration: underline;
            transform: scale(1.2);/* 在 hove 上放大字体大小r */
            transition: transform 0.3s ease, background-color 0.3s ease;/* 两个属性的平滑过渡 */
        }

        .container .footer {
            width: 100%;
            height: 50px;
            text-align: center;
            line-height: 50px;
            color: #ccc;
            margin-top: 15px;
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 导航栏， 功能不实现-->
        <div class="navbar">
            <a href="/">首页</a>
            <a href="/all_questions">题库</a>
            <a href="#">竞赛</a>
            <a href="/chat_page">讨论</a>
            <a href="#">求职</a>
            <a class="login" href="/loginhtml" id="login-link">{{usr}}</a>
        </div>
        <div class="question_list">
            <h1>OnlineJuge题目列表</h1>
            <table>
                <tr>
                    <th class="item">编号</th>
                    <th class="item">标题</th>
                    <th class="item">难度</th>
                </tr>
                {{#question_list}}
                <tr>
                    <td class="item">{{number}}</td>
                    <td class="item"><a href="/question/{{number}}">{{name}}</a></td>
                    <td class="item">{{star}}</td>
                </tr>
                {{/question_list}}
            </table>
        </div>
        <div class="footer">
            <!-- <hr> -->
            <h4>@666</h4>
        </div>
    </div>
    <script>
        //消除指定cookie值
        function clearCookie(name) {
            document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
        }
        $('#login-link').click(function (event) {
            if ($.cookie('sessionId')) {
                event.preventDefault();
                clearCookie("sessionId");
                alert('你退出登录了');
                window.location.href = window.location.href;
            }
        });

        $(document).ready(function () {
            // Function to set the color based on the difficulty level
            function setDifficultyColor() {
                $('.question_list table tr').each(function () {
                    var difficulty = $(this).find('td:nth-child(3)').text().trim();
                    var color;
                    if (difficulty === '简单') {
                        color = 'green';
                    } else if (difficulty === '中等') {
                        color = 'yellow';
                    } else if (difficulty === '困难') {
                        color = 'red';
                    }
                    $(this).find('td:nth-child(3)').css('color', color);
                });
            }

            // 调用该函数以最初设置颜色
            setDifficultyColor();

            // 如果表内容是动态更新的，请再次调用
            // 例如，如果您有一个更新表
            // $(document).ajaxComplete(function() {
            //     setDifficultyColor();
            // });
        });
    </script>
</body>

</html>